package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.itheima.pojo.*;
import org.springframework.web.bind.annotation.*;

@RestController("UserOrderController")
@Slf4j
@RequestMapping("/order")
public class OrderController {


    @Autowired
    private OrderService orderService;


    //提交预约体检
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestBody OrderDTO orderDTO) {
        log.info("提交预约体检:{}",orderDTO);
        try{
            orderService.submitOrder(orderDTO);
            return new Result(true, MessageConstant.ORDER_SUCCESS);
        }
        catch (Exception e){
            log.error("预约体检失败:{}",e.getMessage(),e);
            return new Result(false,"预约设置失败");
        }
    }

    //根据id查询预约信息
    @GetMapping("/findById")
    public Result findById(@RequestParam("id") Integer id) {
        log.info("根据id查询预约信息:{}",id);
        try{
            OrderVO orderVO = orderService.findById(id);
            return new Result(true,MessageConstant.QUERY_ORDER_SUCCESS,orderVO);
        }
        catch (Exception e){
            log.error("根据id查询预约信息失败:{}",e.getMessage(),e);
            return new Result(false,MessageConstant.QUERY_ORDER_FAIL);
        }
    }

}
